package com.course.config;
/*
@author By 林中小鸟
@package  com.self.introduction.com.self.introduction
@create 2021 - 09 - 2021\9\23 0023
@QQ: 357182695
@Em: themooncss@gmail.com
*/

import com.course.interceptor.AuthInterceptor;
import com.course.interceptor.MyInterceptor;
import com.course.interceptor.RoleInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class MasterConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        List<String> handler = new ArrayList<>();
        List<String> exclude = new ArrayList<>();

        /*//拦截器
        handler.add("/**");//  /** 拦截所有请求   /**是指的所有数据。
        //过滤登陆
        exclude.add("/x/login");
        exclude.add("/x/token");
        registry.addInterceptor(authInterceptor()).excludePathPatterns(exclude).addPathPatterns(handler);
        handler.clear();
        exclude.clear();*/


        /*//拦截器
        //角色——权限  实现鉴权
        handler.add("/demo");
        registry.addInterceptor(roleInterceptor()).addPathPatterns(handler);
        handler.clear();
        exclude.clear();
        */

        /*//拦截器
        //自定义  实现鉴权
        handler.add("/demo");
        registry.addInterceptor(myHandlerInterceptor()).addPathPatterns(handler);
        handler.clear();
        exclude.clear();
        */
    }

    // swagger 静态资源
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("doc.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }

    @Bean
    public AuthInterceptor authInterceptor(){
        return new AuthInterceptor();
    }

    @Bean
    public MyInterceptor myHandlerInterceptor(){
        return new MyInterceptor();
    }

    @Bean
    public RoleInterceptor roleInterceptor(){
        return new RoleInterceptor();
    }
}
